function shopping(userId){
    var total=0;
    var $shopping=$(".car_bg").empty();
    $.ajax({
        url:"easybuy/shopping",
        dataType:"json",
        async:false,
        data:{
            userId:userId
        },
        success:function (data) {
            if (data!=null){
                if (data == null||data=="") {
                    $(".car_t").html("购物车 [ <span>0</span> ]");
                    $shopping.append("<div class=\"price_sum\">还未添加任何商品！</div>");
                    $shopping.append("<div class=\"price_a\"><a href='BuyCar.html'>去购物车结算</a></div>");
                }else{
                    $(".car_t").html("购物车 [ <span>"+data.length+"</span> ]")
                    var $ul=$("<ul class=\"cars\"></ul>");
                    for (var i in data) {
                        total=total+parseFloat(data[i].cost);
                        var li=$("<li></li>").html("<div class=\"img\"><a href='Product.html?id="+data[i].id+"'><img src='images/"+data[i].fileName+"' width=\"58\" height=\"58\" /></a></div>\n" +
                            "<div class=\"name\"><a href='Product.html?id="+data[i].id+"'>"+data[i].name+"</a></div>\n" +
                            "<div class=\"price\"><font color=\"#ff4e00\">￥"+data[i].price+"</font> X"+data[i].quantity+"</div>")
                        $($ul).append(li);
                    }
                    $shopping.append($ul);
                    $shopping.append("<div class=\"price_sum\">共计&nbsp; <font color=\"#ff4e00\">￥</font><span>"+total+"</span></div>")
                    $shopping.append("<div class=\"price_a\"><a href='BuyCar.html'>去购物车结算</a></div>")
                }
              }else {
                $shopping.append("<div class=\"un_login\">还未登录！<a href=\"Login.html\" style=\"color:#ff4e00;\">马上登录</a> 查看购物车！</div>")
                $(".car_t").html("购物车 [ <span>0</span> ]");
                $(".price_sum").html("还未添加任何商品！");
            }
        }
    })
    return total;
}
$(function () {
    var user=JSON.parse(sessionStorage.getItem("user"));
    if (user == null){
        $(".car_t").html("购物车 [ <span>0</span> ]")
        $(".car_bg").html("<div class='un_login'>还未登录！<a href='Login.html' style='color:#ff4e00;'>马上登录</a> 查看购物车！</div>")
    }else {
        shopping(user.id);
    }
})